package com.sk.mybatis.tools;

import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class Column {
    private static Map<String, String> map = new HashMap<>();

    //数据类型映射
    static {
        map.put("VARCHAR", "String");
        map.put("TEXT", "String");
        map.put("MEDIUMTEXT", "String");
        map.put("DATE", "Date");
        map.put("TIMESTAMP", "Date");
        map.put("DATETIME", "Date");
        map.put("TINYINT", "int");
        map.put("INT", "int");
        map.put("SMALLINT", "int");
        map.put("BIGINT", "long");
        map.put("CHAR", "String");
        map.put("LONGTEXT", "String");
        map.put("JSON", "String");
        map.put("DECIMAL", "BigDecimal");
        map.put("DOUBLE", "Double");
        map.put("BIT", "boolean");
        map.put("FLOAT", "Double");
        map.put("BIGINT UNSIGNED", "int");

    }

    private String name;
    private String remarks;
    private String columnName;
    private String type;

    public Column(String columnName, String remarks, String type) {
        this.type = map.get(type);
        System.out.println(this.type + ":" + type);
        setColumnName(columnName);
        this.remarks = remarks;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }

    public String getColumnName() {
        return columnName;
    }

    public void setColumnName(String columnName) {
        String[] split = columnName.split("_");
        for (int i = 1; i < split.length; i++) {
            split[i] = split[i].substring(0, 1).toUpperCase() + split[i].substring(1);
        }
        this.name = StringUtils.join(Arrays.asList(split), "");
        this.columnName = columnName;
    }

}
